<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-model数据双向绑定指令</title>
</head>
<body>
    <div id="app">
        <h2>{{msg}}</h2>
        <input type="text" v-model="msg"/>
        <div>
            <p>用户名:  <input type="text" v-model="user.name"/></p>
            <p>性别:    <input type="text" v-model="user.sex"/></p>
            <p>联系方式:<input type="text" v-model="user.phone"/></p>
            <p>家庭住址:<input type="text" v-model="user.address"/></p>
            <button @click="saveuser(user)">保存</button>
        </div>
        <table border="1px">
            <tr>
                <td>用户名</td>
                <td>性别</td>
                <td>联系方式</td>
                <td>家庭住址</td>
                <td>操作</td>
            </tr>
            <tr v-for="(user,index) in users" :key="index">
                <td>{{p.name}}</td>
                <td>{{p.sex}}</td>
                <td>{{p.phone}}</td>
                <td>{{p.address}}</td>
                <td><button">删除</button></td>
            </tr>
        </table>
    </div>
</body>
</html>
<script src="./js/2.7.14_dist_vue.js"></script>
<script>
    new Vue({
        el:"#app",
        data:{
            msg:"Hello Vue!",
            user:{},//定义空对象user
            users:[]    //定义空数组
        },
        methods: {
            saveuser(user){
                this.users.push(user),
                this.user = {};
            }
        },

    })
</script>